﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Bortosky.Google.Visualization;
using IL2SWAUtilities;

namespace IL2SWA
{
    public partial class PlaneDetails : System.Web.UI.Page
    {
        
        [WebMethod]
        public static string GetPlaneFuel()
        {
            
            DataTable resultsRepPlaneFuelDetailsGetByPlaneID = new DataTable();
            resultsRepPlaneFuelDetailsGetByPlaneID = IL2SWAUtilities.DataAccess.RunSP( "RepPlaneFuelDetailsGetByPlaneID", new string[] { "@PlaneID" }, new object[] { 258 });
            var googleDataTable = new Bortosky.Google.Visualization.GoogleDataTable(resultsRepPlaneFuelDetailsGetByPlaneID);
            return googleDataTable.GetJson();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                DataTable resultsPlaneDetails = new DataTable();
                resultsPlaneDetails = IL2SWAUtilities.DataAccess.RunSP( "[RepPlaneDetailsGet]", new string[] { }, new object[] { });
                PlanesFlownInGame.DataSource = resultsPlaneDetails;
                PlanesFlownInGame.DataTextField = resultsPlaneDetails.Columns[1].ToString();
                PlanesFlownInGame.DataValueField = resultsPlaneDetails.Columns[0].ToString();
                PlanesFlownInGame.DataBind();
                SelectedPlane.Text = "";
                SelectedPlane.Visible = false;
                PlaneDetailsLabel.Text = "";
                PlaneDetailsLabel.Visible = false;

                if (Request.QueryString["PlaneName"] != null)
                {
                    PlanesFlownInGame.SelectedIndex = PlanesFlownInGame.Items.IndexOf(PlanesFlownInGame.Items.FindByText(Request.QueryString["PlaneName"]));
                    PlanesFlownInGame_SelectedIndexChanged(PlanesFlownInGame, null);
                }

            }
        }

        protected void PlanesFlownInGame_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            //planeID = PlanesFlownInGame.SelectedValue;
            SelectedPlane.Text = "Mission Data For " + PlanesFlownInGame.SelectedItem.ToString();
            SelectedPlane.Font.Bold = true;
            SelectedPlane.Visible = true;

            IL2SWAUtilities.UIControls.BindGrid(PlanesFlownOverView, "RepPlaneDetailsGetByID", new string[] { "@PlaneID" }, new object[] { PlanesFlownInGame.SelectedValue });
            IL2SWAUtilities.UIControls.BindGrid(PlanePilotDetails,"RepPlanePilotsDetailsGetByPlaneID", new string[] { "@PlaneID" }, new object[] { PlanesFlownInGame.SelectedValue });
            IL2SWAUtilities.UIControls.BindGrid(PlaneLoadoutDetail, "RepPlaneLoadoutDetailsGetByPlaneID", new string[] { "@PlaneID" }, new object[] { PlanesFlownInGame.SelectedValue });
            IL2SWAUtilities.UIControls.BindGrid(PlaneFuelDetail, "RepPlaneFuelDetailsGetByPlaneID", new string[] { "@PlaneID" }, new object[] { PlanesFlownInGame.SelectedValue });
            

        }
    
    }
}